function squareRoot(number) {
  if (number < 0) {
    throw new Error('Cannot calculate the square root of a negative number.');
  }

  let low = 0;
  let high = number;
  let precision = 0.00001; // 精度，可以根据需要调整

  while (high - low > precision) {
    let mid = low + (high - low) / 2;
    let square = mid * mid;

    if (square === number) {
      return mid;
    } else if (square < number) {
      low = mid;
    } else {
      high = mid;
    }
  }

  return low; // 或者返回 high，它们此时非常接近
}

// 示例
let number = 9;
let squareRootValue = squareRoot(number);
console.log(`The square root of ${number} is approximately ${squareRootValue}`);

export {};
